package com.mindskip.xzs.domain.vo.admin.user;

import com.mindskip.xzs.domain.entity.User;
import com.mindskip.xzs.utility.DateTimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

@ApiModel(description = "返回的用户信息")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserVO {

    @ApiModelProperty(value = "用户id")
    private Integer id;

    @ApiModelProperty("用户uuid")
    private String userUuid;

    @ApiModelProperty("用户名")
    private String userName;

    @ApiModelProperty("真实姓名")
    private String realName;

    @ApiModelProperty(value = "年龄")
    private Integer age;

    @ApiModelProperty(value = "角色")
    private Integer role;

    @ApiModelProperty(value = "性别")
    private Integer sex;

    @ApiModelProperty(value = "出生日期")
    private String birthDay;

    @ApiModelProperty(value = "手机号")
    private String phone;

    @ApiModelProperty(value = "最后活动时间")
    private String lastActiveTime;

    @ApiModelProperty(value = "创建时间")
    private String createTime;

    @ApiModelProperty(value = "修改时间")
    private String modifyTime;

    @ApiModelProperty(value = "状态")
    private Integer status;

    @ApiModelProperty(value = "年级")
    private Integer userLevel;

    @ApiModelProperty(value = "头像")
    private String imagePath;


    // 将 User 转为 UserVO
    public static UserVO from(User user) {
        UserVO userVO = new UserVO();
        BeanUtils.copyProperties(user, userVO);
        // BeanUtils 无法将 User 中的 Date 类型属性转为 UserVO 中的 String 类型属性
        // 所以手动将日期类型转换为String类型 "yyyy-MM-dd HH:mm:ss"
        userVO.setBirthDay(DateTimeUtil.dateFormat(user.getBirthDay()));
        userVO.setLastActiveTime(DateTimeUtil.dateFormat(user.getLastActiveTime()));
        userVO.setCreateTime(DateTimeUtil.dateFormat(user.getCreateTime()));
        userVO.setModifyTime(DateTimeUtil.dateFormat(user.getModifyTime()));
        return userVO;
    }
}
